<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../layui.css">
</head>
<body>        
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
</fieldset>

<form class="layui-form" action="/admin/detials/save" method="post">

  <div class="layui-form-item">
    <div class ="layui-inline">
    <label class="layui-form-label">编号</label>
      <div class="layui-input-inline">
        <input type="text" name="id" required  lay-verify="required" autocomplete="off" class="layui-input id" disabled="disabled">
      </div>
    </div>
    <div class ="layui-inline">
    <label class="layui-form-label">申请编号</label>
      <div class="layui-input-inline">
        <input type="text" name="applySerial" required  lay-verify="required" autocomplete="off" class="layui-input applySerial" disabled="disabled">
      </div>
    </div>
  </div>
  <div class="layui-form-item">
    <div class = "layui-inline">
      <label class = "layui-form-label">教材去处</label>
      <div class= "layui-input-inline">
        <input type="text" name="grade" lay-verify="required" autocomplete="off" class ="layui-input grade" disabled="disabled">
      </div>
    </div>
    <div class = "layui-inline">
      <label class = "layui-form-label">课程名称</label>
      <div class= "layui-input-inline">
        <input type="text" name="courseName" autocomplete="off" class ="layui-input courseSerial courseName" disabled="disabled">
      </div>
    </div>
  </div>

  <div class="layui-form-item">
    <div class = "layui-inline">
      <label class = "layui-form-label">教材1名称</label>
      <div class= "layui-input-inline">
        <input type="text" name="name"   autocomplete="off" class ="layui-input name" disabled="disabled">
      </div>
    </div>
    <div class = "layui-inline">
      <label class="layui-form-label">征订数量</label>
      <div class="layui-input-inline">
        <input type="text" name="quantity" lay-verify="required" placeholder="请输入数量" autocomplete="off" class ="layui-input  quantity">
      </div>
    </div>
  </div>
  <div class="layui-form-item">
    <div class = "layui-inline">
      <label class = "layui-form-label">教材2名称</label>
      <div class= "layui-input-inline">
        <input type="text" name="secondName"   autocomplete="off" class ="layui-input secondName" disabled="disabled">
      </div>
    </div>
    <div class = "layui-inline">
      <label class="layui-form-label">征订数量</label>
      <div class="layui-input-inline">
        <input type="text" name="sQuantity" lay-verify="required" placeholder="请输入数量" autocomplete="off" class ="layui-input  sQuantity">
      </div>
    </div>
  </div>
  <div class="layui-form-item">
    <div class = "layui-inline">
      <label class = "layui-form-label">教材3名称</label>
      <div class= "layui-input-inline">
        <input type="text" name="thirdName"   autocomplete="off" class ="layui-input thirdName" disabled="disabled">
      </div>
    </div>
    <div class = "layui-inline">
      <label class="layui-form-label">征订数量</label>
      <div class="layui-input-inline">
        <input type="text" name="tQuantity" lay-verify="required" placeholder="请输入数量" autocomplete="off" class ="layui-input  tQuantity">
      </div>
    </div>
  </div>

  <div class = "layui-form-item">
    <div class = "layui-inline">
      <label class="layui-form-label">征订人</label>
      <div class="layui-input-inline">
        <input type="text" name="tName" autocomplete="off" class ="layui-input courseSerial tName" disabled="disabled">
      </div>
    </div>
    <div class = "layui-inline">
      <label class = "layui-form-label">联系方式</label>
      <div class= "layui-input-inline">
        <input type="text" name="telephone" lay-verify="required" placeholder="请输入联系方式" autocomplete="off" class ="layui-input telephone">
      </div>
    </div>
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="formDemo">保存</button>
    </div>
  </div>
</form>
<script src="../layui.js" charset="utf-8"></script>
<script src="../jquery-3.1.1.min.js"></script>



<script>



//获取参数
function getQueryVariable(variable){
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
    }
    return(false);
}

layui.use(['form', 'layedit', 'laydate'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,upload = layui.upload
  ,laydate = layui.laydate;

  var $ =layui.jquery;

  setMessage();

//填充申请信息
  function setMessage(){
  var a = getQueryVariable("applySerial");
  $.ajax({
      url:"/admin/detials/bySerial",
      type:"post",
      dataType:"json",
      data:{"applySerial":a},
      success:function(result){
      var message = result.data;
      console.log(message);
      $(".id").val(message.id);
      $(".applySerial").val(message.applySerial);
      $(".grade").val(message.grade);
      $(".name").val(message.name);
      $(".courseName").val(message.courseName);
      $(".quantity").val(message.quantity);
      $(".tName").val(message.tName);
      $(".telephone").val(message.telephone);
      $(".secondName").val(message.secondName);
      $(".sQuantity").val(message.sQuantity);
      $(".thirdName").val(message.thirdName);
      $(".tQuantity").val(message.tQuantity);
      },
      error:function(result){
        console.log(result.msg);
      }
    })
  };


  //日期
  laydate.render({
    elem: '#date'
  });
  //创建一个编辑器
  var editIndex = layedit.build('LAY_demo_editor');
 
  //自定义验证规则

  //以后要留下的验证区域

  form.verify({
    title: function(value){
      if(value.length < 5){
        return '标题至少得5个字符啊';
      }
    }
    ,pass: [/(.+){6,12}$/, '密码必须6到12位']
    ,content: function(value){
      layedit.sync(editIndex);
    }
  });

  
  //监听提交
  
  form.on('submit(formDemo)', function(data){
    var data = data.field;
    var temp =0;
    console.log(data);
    if(!((data.secondName===""&&data.sQuantity==="")||(data.secondName!=""&&data.sQuantity!=""))){
      layer.confirm("数量输入有误");
    }else{
      temp = 1;
    }
    //教材3选择问题
    if(!((data.thirdName===""&&data.tQuantity==="")||(data.thirdName!=""&&data.tQuantity!=""))){
      temp = 0;
      layer.confirm("数量输入有误");
    }else{
      temp = 1;
    }
    if(temp===1){
      saveDetials(data);
    }
    
/*    saveDetials(data.applySerial,data.grade,data.name,data.telephone,data.quantity,data.courseName,data.tName);
    saveApply(data.applySerial,data.tSerial);*/
    return false;
  });


});

function saveDetials(message){

  console.log(message.tName);
  $.ajax({
    url:"/admin/detials/updata",
    type:"post",
    dataType:"json",
    data:{
      "id":message.id,
      "applySerial":message.applySerial,
      "grade":message.grade,
      "name":message.name,
      "telephone":message.telephone,
      "quantity":message.quantity,
      "courseName":message.courseName,
      "tName":message.tName,
      "secondName":message.secondName,
      "thirdName":message.thirdName,
      "sQuantity":message.sQuantity,
      "tQuantity":message.tQuantity
    },
    success:function(result){
      alert("修改成功");
    },
    error:function(result){
      console.log("sb");
    }
  })
}

</script>

</body>
</html>